package br.diego.tb.generalinterviews;

public class MissingNumber 
{
	public static void main(String[] args) {
		Integer a = 2;
		Integer b = 3;
		
		int sum = a + b;
		System.out.println(sum);
	}
	public static void find_missing_number(Integer[] v) {
		
		int totalSum = 0;
		
		int lowest = 0;
		int highest = 0;
		
		for(int value : v)
		{
			lowest = (value < lowest) ? value : lowest;
			highest = (value > highest) ? value : highest;
			
			totalSum += value;
		}
		
		int missingNumber = sumValuesInRange(lowest, highest) - totalSum;
		
		System.out.println(missingNumber);
		
		
		
	}
	
	private static int sumValuesInRange(int beginning, int end)
	{
		int totalNumbersInRange = end - beginning + 1;
		
		int sumByArithmeticProgression = (beginning + end)*totalNumbersInRange/2;
		
		return sumByArithmeticProgression;
	}
	
	
	
}
